<html>
<head>
    <meta charset="utf-8">
    <title>Parsleyjs Mocha Tests</title>
    <link rel="stylesheet" href="mocha.css" />
    <script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-XXXXXXXXX-X']);
      _gaq.push(['_trackPageview']);

      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();

    </script>
    <script type="text/javascript">
        function pause ( ms ) {
            ms += new Date().getTime();
            while ( new Date() < ms ){}
        }

        function jsAppend ( js_file, fn ) {
          if ( 'string' === typeof js_file ) {
              js_file = [ js_file ];
          }

          for ( var i in js_file ) {
              var js_script = document.createElement( 'script' );
              js_script.type = "text/javascript";
              js_script.src = js_file[ i ];
              document.getElementsByTagName( 'head' )[ 0 ].appendChild( js_script );
          }

          return 'function' == typeof fn ? fn() : true;
        }
    </script>
</head>
<body>
    <div id="info"></div>
    <div id="mocha"></div>

    <div style="display: none;">
        <form parsley-validate>
            <input type="text" id="input1" parsley-minlength="6" parsley-trigger="change keyup" />
            <input type="hidden" id="hidden" />
            <textarea id="textarea1"></textarea>
        </form>
        <form data-parsley-validate>
            <input type="text" id="input1-1" parsley-minlength="6" parsley-trigger="change keyup" />
            <input type="hidden" id="hidden1-1" />
            <textarea id="textarea1-1"></textarea>
        </form>
        <form>
            <input type="text" id="input2" parsley-validate parsley-type="email" />
            <textarea id="textarea2"></textarea>
        </form>
        <form parsley-validate>
            <input type="text" id="errormanagement" parsley-minlength="6" parsley-maxlength="10" parsley-type="alphanum" />
            <input type="text" id="errorMessage" parsley-error-message="This is my <strong>custom</strong> message" parsley-minlength="20" parsley-type="email" />
        </form>
        <form id="priorityForm">
            <input id="priorityValidator" type="text" parsley-type="email" parsley-minlength="15" />
        </form>
        <form id="validator-tests" parsley-validate>
            <input type="text" id="notnull" parsley-notnull="true" />
            <input type="text" id="notblank" parsley-notblank="true" />

            <input type="text" id="required" parsley-required="true" />
            <input type="text" id="required-class" class="required" />
            <input type="text" id="required-html5" required="required" />
            <input type="text" id="required-html5-bis" required />
            <select id="required-selectmultiple" multiple="multiple" name="selectmultiple" parsley-required="true">
                <option value="">Select</option>
                <option value="foo">foo</option>
                <option value="bar">bar</option>
            </select>

            <input type="text" id="minlength" parsley-minlength="6" />
            <input type="text" id="maxlength" parsley-maxlength="6" />
            <input type="text" id="rangelength" parsley-rangelength="[6,10]" />
            <input type="text" id="min" parsley-min="10" />
            <input type="text" id="max" parsley-max="10" />
            <input type="number" id="min-html5" min="10" />
            <input type="number" id="max-html5" max="10" />

            <input type="text" id="range" parsley-range="[6,10]" />

            <input type="text" id="regexp" parsley-regexp="\d+" />
            <input type="text" id="regexp-html5" pattern="\d+" />
            <input type="text" id="regexp-flag1" parsley-regexp="^[A-Z]" />
            <input type="text" id="regexp-flag2" parsley-regexp="^[A-Z]" parsley-regexp-flag="i" />

            <input type="text" id="typeemail" parsley-type="email" />
            <input type="email" id="typeemail-html5" />

            <input type="range" id="typerange-html5" min="5" max="10" />

            <input type="text" id="typeurl" parsley-type="url" />
            <input type="url" id="typeurl-html5" />

            <input type="text" id="typeurlstrict" parsley-type="urlstrict" />
            <input type="text" id="typedigits" parsley-type="digits" />
            <input type="text" id="typenumber" parsley-type="number" />
            <input type="text" id="typedateIso" parsley-type="dateIso" />
            <input type="text" id="typealphanum" parsley-type="alphanum" />
            <input type="text" id="typephone" parsley-type="phone" />
            <input type="tel" id="typephone2" />

            <input type="text" id="customvalidator" parsley-multiple="9" />

            <input type="text" id="equalTo-model" value="foobar" />
            <input type="text" id="equalTo" parsley-equalTo="#equalTo-model" />

            <input type="checkbox" id="checkbox-mincheck1" name="mincheck[]" value="foo" parsley-mincheck="2" />
            <input type="checkbox" id="checkbox-mincheck2" name="mincheck[]" value="bar" />

            <input type="checkbox" id="checkbox-mincheckgroup1" value="foo" parsley-group="foo" parsley-mincheck="2" />
            <input type="checkbox" id="checkbox-mincheckgroup2" value="bar" parsley-group="foo" />

            <input type="checkbox" id="checkbox-maxcheck1" name="maxcheck[]" value="foo" parsley-maxcheck="2" parsley-trigger="change"/>
            <input type="checkbox" id="checkbox-maxcheck2" name="maxcheck[]" value="bar" />
            <input type="checkbox" id="checkbox-maxcheck3" name="maxcheck[]" value="baz" />

            <input type="checkbox" id="checkbox-rangecheck1" name="rangecheck[]" value="foo" parsley-rangecheck="[2,3]" />
            <input type="checkbox" id="checkbox-rangecheck2" name="rangecheck[]" value="bar" />
            <input type="checkbox" id="checkbox-rangecheck3" name="rangecheck[]" value="baz" />
            <input type="checkbox" id="checkbox-rangecheck4" name="rangecheck[]" value="boz" />

            <input type="checkbox" id="checkbox-maxcheckchange1" name="maxcheckchange[]" value="foo" parsley-maxcheck="2" />
            <input type="checkbox" id="checkbox-maxcheckchange2" name="maxcheckchange[]" value="bar" />
            <input type="checkbox" id="checkbox-maxcheckchange3" name="maxcheckchange[]" value="baz" />

            <input type="text" id="remote1" name="remote1" parsley-remote="http://foo.bar" parsley-remote-datatype="jsonp" />
            <input type="text" id="remote2" name="remote2" parsley-remote="http://foo.bar/baz" parsley-trigger="change" parsley-remote-method="POST" />

            <input type="text" id="datavalue1" name="datavalue1" parsley-value="" value="" parsley-required="true" />
            <input type="text" id="datavalue2" name="datavalue2" parsley-value="foo" value="" parsley-required="true" />

            <input type="submit" />
        </form>
        <form id="html5-constraints-disabled" parsley-use-html5-constraints="false" parsley-validate>
            <input type="tel" id="html5-constraints-disabled-1" parsley-regexp="^[A-Z]*$" />
            <input type="email" id="html5-constraints-disabled-2" parsley-regexp="\d+$" />
            <input type="text" id="html5-constraints-disabled-3" pattern="[0-9]*" minlength="5" parsley-regexp="^[A-Z]*$" />
            <input type="text" id="html5-constraints-disabled-4" required />
        </form>
        <form id="validate-form" parsley-validate>
            <input type="text" id="validate1" parsley-required="true" />
            <input type="text" id="validate2" parsley-minlength="6" />
            <input type="submit" id="validate-form-submit" />
        </form>
        <form id="change-validation" parsley-validate>
            <input type="text" id="minchar-change" parsley-type="email" parsley-trigger="keyup" parsley-validation-minlength="7" />
        </form>
        <form id="change-show-errors" parsley-show-errors="false">
            <input type="text" id="change-show-errors-field1" parsley-type="email" parsley-trigger="keyup" parsley-validation-minlength="0" />
            <input type="text" id="change-show-errors-field2" parsley-type="url" />
        </form>
        <form id="requiredchanged1-form">
            <input type="text" id="requiredchanged1" parsley-required="true" />
        </form>
        <form id="requiredchanged2-form">
            <input type="text" id="requiredchanged2" parsley-required="true" />
            <input type="text" id="requiredchanged3" parsley-required="true" parsley-type="email" parsley-required-message="custom required" parsley-type-email-message="custom email" />
        </form>
        <form id="updateconstraint-form">
            <input type="text" id="updateconstraint1" parsley-required="true" parsley-required-message="required error" />
            <input type="text" id="updateconstraint2" parsley-type="email" parsley-type-email-message="email error" />
            <input type="text" id="updateconstraint3" parsley-type="number" parsley-type-number-message="number error" />
        </form>
        <form id="errorsmanagement-form">
            <label id="errorsmanagement-labelinfo"></label>
            <label id="errorsmanagement-labelerror"></label>
            <input type="text" id="errorsmanagement-email" parsley-type="email" />
        </form>

        <form id="validation-scenarios" parsley-validate>
            <input type="text" id="scenario-multiple-errors-and-required" parsley-required="true" parsley-type="email" parsley-rangelength="[20,50]" >
            <input type="text" id="scenario-not-required" parsley-trigger="keyup" parsley-minlength="6" />
            <input type="text" id="scenario-keyup-when-notvalid" parsley-trigger="change" parsley-type="email" />
            <input type="text" id="scenario-validation-after-field-reset" parsley-trigger="keyup" parsley-required="true" />
            <select id="scenario-validation-change-select" parsley-required="true">
                <option value="">Chose</option>
                <option value="foo">foo</option>
                <option value="bar">bar</option>
            </select>
        </form>
        <form parsley-validate id="focus-form" parsley-focus="last">
            <input type="text" id="focus1" parsley-type="email" parsley-required="true" />
            <input type="text" id="focus2" parsley-type="email" parsley-required="true" />
        </form>
        <form parsley-validate id="focus-form2" parsley-focus="none">
            <input type="text" id="focus3" parsley-type="email" parsley-required="true" />
            <input type="text" id="focus4" parsley-type="email" parsley-required="true" />
        </form>
        <form parsley-validate id="hidden-input-form">
            <input type="text" id="hidden-input1" parsley-type="email" parsley-required="true" />
            <input type="hidden" id="hidden-input2" />
        </form>
        <form parsley-validate id="destroy">
            <input type="text" parsley-type="email" id="destroy-email" parsley-trigger="change" />
            <input type="select" id="destroy-multiple" parsley-required="true"></input>
        </form>
        <form parsley-validate id="reset">
            <input type="text" id="reset-email" parsley-required="true" />
            <textarea id="reset-textarea" parsley-required="true"></textarea>
        </form>
        <form parsley-validate id="dynamic-form" parsley-triggers="keyup change">
        </form>
        <form parsley-validate id="onthefly-form">
            <input type="text" id="onthefly" />
        </form>
        <form dat-validate="parsley" id="dataerrorcontainer-form">
            <input id="dataerrorcontainer" type="text" required parsley-error-container="#mycustomerrorcontainer" />
        </form>
        <form dat-validate="parsley" id="isValid-form">
            <input id="isValid-field" type="text" required />
        </form>
        <form id="api-calls-form" data-validate="parsley">
            <input type="text" id="programmableField" required value="filled"/>
            <input type="submit" />
        </form>
        <div id="mycustomerrorcontainer"></div>
        <form parsley-validate id="onFieldValidate-form">
            <input type="text" id="onFieldValidate1" parsley-type="email" parsley-required="true" />
            <input type="text" id="onFieldValidate2" parsley-type="email" parsley-required="true" />
        </form>
        <form id="alwaysValidate-form">
            <input type="text" id="alwaysValidate" parsley-type="email" />
        </form>
        <form parsley-validate id="listeners-form">
            <input type="text" id="listeners1" parsley-type="email" parsley-required="true" />
        </form>
        <form parsley-validate id="onFieldValidatetrue-form">
            <input type="text" id="onFieldValidatefalse" parsley-type="email" parsley-required="true" />
            <input type="text" id="onFieldValidatetrue" parsley-type="email" parsley-required="true" />
        </form>
        <form parsley-validate id="addListenerFieldValidate">
            <input type="text" id="addListenerFieldValidate-field" parsley-type="email" parsley-required="true" />
        </form>
        <form id="onFormValidateCustom">
            <input type="text" id="onFormValidateCustom-field" parsley-type="email" parsley-required="true" />
        </form>
        <form parsley-validate id="radiocheckboxes">
            <div id="radio-parent">
                <input type="radio" id="radio1" name="radio" value="radio1" />
                <input type="radio" id="radio2" name="radio" value="radio2" required />
            </div>
            <div id="check_parent">
                <input type="checkbox" id="check1" name="check[]" value="check1" required />
                <input type="checkbox" id="check2" name="check[]" value="check2" required />
            </div>
        </form>

        <form id="dom-api" parsley-validate data-parsley-namespace="data-parsley-">
            <input type="text" id="dom-api-input" data-parsley-minlength="15" />
        </form>

        <form parsley-validate>
            <input type="text" id="minwords" parsley-minwords="6" />
            <input type="text" id="maxwords" parsley-maxwords="6" />
            <input type="text" id="rangewords" parsley-rangewords="[6, 10]" />
            <input type="text" id="greaterThan-model" value="1" />
            <input type="text" id="greaterThan" parsley-greaterthan="#greaterThan-model" />
            <input type="text" id="lessThan-model" value="2" />
            <input type="text" id="lessThan" parsley-lessthan="#lessThan-model" />
            <input type="text" id="beforeDate-model" value="1/1/2014" />
            <input type="text" id="beforeDate" parsley-beforedate="#beforeDate-model" />
            <input type="text" id="afterDate-model" value="1/1/2014" />
            <input type="text" id="afterDate" parsley-afterdate="#afterDate-model" />
            <input type="text" id="inList" parsley-inlist="true, 1, valid, value with spaces, yes, one" />
            <input type="text" id="inListSingleValue" parsley-inlist="true" />
            <input type="text" id="inListEmpty" parsley-inlist="" />
            <input type="text" id="inListSingleComma" parsley-inlist="," />
            <input type="text" id="inListCustomDelimiter" parsley-inlist="foo | bar | foo bar" parsley-inlist-delimiter="|" />

            <input type="text" id="luhn" parsley-luhn="true" />
            <input type="text" id="americanDate" parsley-americandate="true" />
            <input type="text" id="es_dni" parsley-es_dni="true" />
            <input type="text" id="es_cif" parsley-es_cif="true" />
            <input type="text" id="es_postalcode" parsley-es_postalcode="true" />
            <input type="text" id="es_ssn" parsley-es_ssn="true" />
            <input type="text" id="es_ccc" parsley-es_ccc="true" />
        </form>

        <div parsley-validate parsley-bind id="parsley-bind">
            <input type="text" id="bindNonFormInput" parsley-required="true" value="" />
        </div>

        <form id="dynamic-excluded" parsley-validate>
            <input type="email" id="dynamic-disabled-email" required />
        </form>
    </div>

    <script type="text/javascript">
        var jquery = 'resources/jquery.min.js'
          , zepto = 'resources/zepto-1.0rc1[zepto.event.data.ajax.fx.fx_modules].js'
          , jquery2x = '../bower_components/jquery/jquery.min.js';

        switch ( location.hash ) {
            case '#zepto':
                jsAppend( zepto , pause( 100 ) );
                jsAppend( '../parsley.js' , pause( 50 ) );
                jsAppend( '../parsley.extend.js' , pause( 50 ) );
                jsAppend( '../l10n/parsley.es.js' , pause( 50 ) );
                document.getElementById( 'info' ).innerHTML = 'Parsley test suite for Zepto, unminified version';
                break;
            case '#zepto-min':
                jsAppend( zepto , pause( 100 ) );
                jsAppend( '../dist/parsley.min.js' , pause( 50 ) );
                jsAppend( '../dist/parsley.extend.min.js' , pause( 50 ) );
                jsAppend( '../dist/parsley.es.min.js' , pause( 50 ) );
                document.getElementById( 'info' ).innerHTML = 'Parsley test suite for Zepto, minified version';
                break;
            case '#jquery-min':
                jsAppend( jquery , pause( 100 ) );
                jsAppend( '../dist/parsley.min.js' , pause( 50 ) );
                jsAppend( '../dist/parsley.extend.min.js' , pause( 50 ) );
                jsAppend( '../dist/parsley.es.min.js' , pause( 50 ) );
                document.getElementById( 'info' ).innerHTML = 'Parsley test suite for jQuery, minified version';
                break;
            case '#jquery-2.x':
                jsAppend( jquery2x , pause( 100 ) );
                jsAppend( '../parsley.js' , pause( 50 ) );
                jsAppend( '../parsley.extend.js' , pause( 50 ) );
                jsAppend( '../l10n/parsley.es.js' , pause( 50 ) );
                document.getElementById( 'info' ).innerHTML = 'Parsley test suite for jQuery 2.0.x, unminified version';
                break;
            default:
                jsAppend( jquery , pause( 100 ) );
                jsAppend( '../parsley.js' , pause( 50 ) );
                jsAppend( '../parsley.extend.js' , pause( 50 ) );
                jsAppend( '../l10n/parsley.es.js' , pause( 50 ) );
                document.getElementById( 'info' ).innerHTML = 'Parsley test suite for jQuery 1.8.x, unminified version';
                break;
        }

        jsAppend( [ 'mocha.js', 'expect.js', 'sinon.js', 'tests.js' ] );

        window.onload = function() {

            mocha.setup( 'bdd' );
            mocha.reporter( 'html' );
            testSuite();

            if ( window.mochaPhantomJS ) {
                mochaPhantomJS.run();
            } else {
                mocha.run();
            }
        };
    </script>
</body>
</html>
